/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package trefliq.EJB.entities;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Adam Gojdas
 */
@Entity
@Table(name = "MOVIEGENRE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MovieGenre.findAll", query = "SELECT m FROM MovieGenre m"),
    @NamedQuery(name = "MovieGenre.findByMovieid", query = "SELECT m FROM MovieGenre m WHERE m.MovieGenrePK.movieid = :movieid"),
    @NamedQuery(name = "MovieGenre.findByGenreid", query = "SELECT m FROM MovieGenre m WHERE m.MovieGenrePK.genreid = :genreid"),
    @NamedQuery(name = "MovieGenre.findByMovieIDGenreid", query = "SELECT m FROM MovieGenre m WHERE m.MovieGenrePK.genreid = :genreid AND m.MovieGenrePK.movieid = :movieid")})
public class MovieGenre implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected MovieGenrePK MovieGenrePK;
    @JoinColumn(name = "GENREID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Genre genre;
    @JoinColumn(name = "MOVIEID", referencedColumnName = "ID", nullable = false, insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Movie movie;

    public MovieGenre() {
    }

    public MovieGenre(MovieGenrePK MovieGenrePK) {
        this.MovieGenrePK = MovieGenrePK;
    }

    public MovieGenre(long movieid, long genre) {
        this.MovieGenrePK = new MovieGenrePK(movieid, genre);
    }

    public MovieGenrePK getMovieGenrePK() {
        return MovieGenrePK;
    }

    public void setMovieGenrePK(MovieGenrePK MovieGenrePK) {
        this.MovieGenrePK = MovieGenrePK;
    }

    public Genre getGenre() {
        return genre;
    }

    public void setGenre(Genre genre) {
        this.genre = genre;
    }

    public Movie getMovie() {
        return movie;
    }

    public void setMovie(Movie movie) {
        this.movie = movie;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (MovieGenrePK != null ? MovieGenrePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MovieGenre)) {
            return false;
        }
        MovieGenre other = (MovieGenre) object;
        if ((this.MovieGenrePK == null && other.MovieGenrePK != null) || (this.MovieGenrePK != null && !this.MovieGenrePK.equals(other.MovieGenrePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "se554.grp3.adg.MovieGenre[ MovieGenrePK=" + MovieGenrePK + " ]";
    }
    
}
